const request = require("request")
const sleep = delay => new Promise(resolve => setTimeout(resolve, delay))

const randomRange = (min, max) => Math.floor(Math.random() * (max + 1 - min) + min)

const syncRequest = (requestOptions) => {
    return new Promise((resolve, reject) => {
        request(requestOptions, (err, rep, data) => {
            if (err) {
                console.error('请求失败：', err)
                reject(err)
            }
            if (data) {
                if (data.code == 200) {
                    resolve(data)
                } else {
                    resolve({
                        data: {
                            data: []
                        }
                    })
                }
            }
        })
    })
}
module.exports = {
    sleep,
    randomRange,
    syncRequest
}